using System;
using System.Collections.Generic;
using System.Text;

namespace GoogleNet
{
    /// <summary>
    /// References a KML file or KMZ archive on a local or remote network. 
    /// Use the Link element to specify the location of the KML file. 
    /// Within that element, you can define the refresh options for updating the file, 
    /// based on time and camera change. 
    /// NetworkLinks can be used in combination with Regions to handle very large datasets efficiently. 
    /// </summary>
    public class KmlNetworkLink : KmlFeature, IKmlElement
    {
        private string tagName = "NetworkLink";

        #region Link
        private KmlLink link = new KmlLink();

        /// <summary>
        /// Specifies the location of any KML files fetched by the network link
        /// </summary>
        /// <value>The link.</value>
        public KmlLink Link
        {
            get { return link; }
            set { link = value; }
        } 
        #endregion

        #region RefreshVisibility
        private bool refreshVisibility;

        /// <summary>
        /// Boolean value (default=0). A value of 0 leaves the visibility of features within the control of the Google Earth user. Set the value to 1 to reset the visibility of features each time the NetworkLink is refreshed. For example, suppose a Placemark within the linked KML file has <visibility> set to 1 and <refreshVisibility> set to 1. When the file is first loaded into Google Earth, the user can clear the check box next to the item to turn off display in the 3D viewer. However, when the network link is refreshed, the item will be made visible again, since its original visibility state was TRUE. 
        /// <remarks>Note: This tag has been superseded by the Update tag, introduced in KML 2.1.</remarks>
        /// </summary>
        /// <value><c>true</c> if [refresh visibility]; otherwise, <c>false</c>.</value>
        [Obsolete("This tag has been superseded by the <Update> tag, introduced in KML 2.1.")]
        public bool RefreshVisibility
        {
            get { return refreshVisibility; }
            set { refreshVisibility = value; }
        } 
        #endregion

        #region FlyToView
        private bool flyToView;

        /// <summary>
        /// Boolean value (default=0). A value of 1 causes Google Earth to fly to the 
        /// view of the root element in the refreshed file. In this case, Google Earth 
        /// flies to the LookAt view of the parent Document, not the LookAt of the Placemarks 
        /// contained within the Document. 
        /// </summary>
        /// <value><c>true</c> if [fly to view]; otherwise, <c>false</c>.</value>
        public bool FlyToView
        {
            get { return flyToView; }
            set { flyToView = value; }
        } 
        #endregion


        #region IKmlElement Members

        /// <summary>
        /// Name of the KML tag for this specific element.
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        string IKmlElement.TagName
        {
            get { return tagName; }
        }

        #endregion

        #region IKmlGenerator Members

        /// <summary>
        /// Generates the KML for this element including its child elements.
        /// </summary>
        /// <param name="writer">The XML writer that will be used to generate the KML.</param>
        public override void GenerateKml(System.Xml.XmlTextWriter writer)
        {
            writer.WriteStartElement(tagName);
            base.GenerateKml(writer);
            link.GenerateKml(writer);
            if (this.refreshVisibility)
                writer.WriteElementString("refreshVisibility", "1");

            if (this.flyToView)
                writer.WriteElementString("flyToView", "1");

            writer.WriteFullEndElement();
        }

        #endregion
    }
}
